<html>

<head>
    <meta charset="utf-8">
    <meta name="author" content="xsl">
    <script src="jquery-3.1.1.js"></script>
    <title>薛胜雷</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        .all{
            width: 160px;
            height: 157px;
            position: absolute;
        }
        ul {
            list-style: none;
            cursor: pointer;
            box-sizing: border-box;
        }
        
        .first {
            display: flex;
            width: 260px;
            line-height: 30px;
            margin: 50px auto;
        }
        
        .first li:nth-child(1) {
            background-color: limegreen;
            width: 100px;
            text-align: center;
        }
        
        .first li:nth-child(2) {
            background-color: #ccc;
            width: 160px;
            text-align: center;
        }
        
        .last {
            width: 160px;
            margin: -49px auto;
            position: relative;
            left: 50px;
            border: 1px solid red;
            display: none;
        }
        
        .last li {
            width: 160px;
            text-align: center;
            height: 30px;
            border-bottom: 1px dashed red;
        }
        
        .last .bgc {
            background-color: #ccc;
        }
    </style>
</head>

<body>
        <ul class="first">
            <li>选择项目:</li>
            <li class="xuan">未选择</li>
        </ul>
        <ul class="last">
            <li>html5</li>
            <li>css3</li>
            <li>javascript</li>
            <li>jquery</li>
        </ul>
    <div class="all">
    </div>
</body>

</html>
<script>
    // 点击显示下拉
    $('.xuan').click(function () {
        $('.last').css('display', 'block')
    })
    // 鼠标放上去改变背景颜色
    $('.last li').mouseover(function () {
        $(this).addClass('bgc').siblings().removeClass('bgc')
    })
    $('.all').mouseleave(function () {
        $('.last').css('display', 'none')
    })
    // 点击获取文本内容
    $('.last li').click(function () {
        $('.xuan').html($(this).text())
        $('.last').css('display', 'none');
    })

</script>